home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #9 / Amiga Plus CD - 2004 - No. 09.iso / amigaplus / games / saga / source / counters.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-08-03  |  22.8 KB  |  635 lines

  1. // 1. INCLUDES -----------------------------------------------------------
  2.  
  3. #include <exec/types.h>
  4. #include <exec/alerts.h>
  5. #include <intuition/intuition.h>
  6. #include <graphics/gfx.h>
  7. #include <graphics/displayinfo.h>
  8. #include <graphics/gels.h>
  9. #include <graphics/view.h>
  10.  
  11. #include <stdlib.h>
  12.  
  13. #include "animtools.h"
  14. #include "saga.h"
  15. #include "counters.h"
  16.  
  17. // 2. DEFINES ------------------------------------------------------------
  18.  
  19. // 3. EXPORTED VARIABLES -------------------------------------------------
  20.  
  21. EXPORT NEWBOB NewBob =
  22. {   NULL,               // initial image
  23.     COUNTERWIDTH,       // width in words
  24.     COUNTERHEIGHT,      // line height
  25.     2,                  // image depth
  26.     1,                  // PlanePick
  27.     0x7F,               // PlaneOnOff
  28.     SAVEBACK | OVERLAY, // VSprite flags
  29.     FALSE,              // double buffer?
  30.     0,                  // raster depth
  31.     HIDDEN_X, HIDDEN_Y, // x, y position (filled later)
  32.     0,                  // hit mask
  33.     0                   // me mask
  34. };
  35.  
  36. // 4. IMPORTED VARIABLES -------------------------------------------------
  37.  
  38. IMPORT struct Custom         custom;
  39.  
  40. IMPORT struct GfxBase*       GfxBase;
  41. IMPORT struct Window        *MainWindowPtr,
  42.                             *InfoWindowPtr;
  43. IMPORT struct WorldStruct    world[36 + 30];
  44. IMPORT struct HeroStruct     hero[HEROES + 1];
  45. IMPORT struct JarlStruct     jarl[JARLS + 1];
  46. IMPORT struct MonsterStruct  monster[MONSTERS + 1];
  47. IMPORT struct TreasureStruct treasure[TREASURES + 1];
  48. IMPORT struct SordStruct     sord[SORDS + 1];
  49. IMPORT UWORD                 DisplayDepth;
  50. IMPORT SLONG                 treasures;
  51.  
  52. // 5. MODULE VARIABLES ---------------------------------------------------
  53.  
  54. MODULE struct GelsInfo*      GInfoPtr = NULL;
  55. MODULE struct Bob           *HeroBobPtr[HEROES + 1],
  56.                             *JarlBobPtr[JARLS + 1],
  57.                             *MonsterBobPtr[MONSTERS + 1],
  58.                             *TreasureBobPtr[TREASURES + 1],
  59.                             *SordBobPtr[SORDS + 1];
  60.  
  61. /* The word `Sword' is deliberately mispelled (within the source code) as
  62.    Sord. This avoids any confusion with the SWORD (signed word) typedef. */
  63.  
  64. // 6. MODULE STRUCTURES --------------------------------------------------
  65.  
  66. // 7. MODULE FUNCTIONS ---------------------------------------------------
  67.  
  68. // 8. CODE ---------------------------------------------------------------
  69.  
  70. AGLOBAL void createcounters(void)
  71. {   SLONG whichhero, whichjarl, whichmonster, whichtreasure, whichsord;
  72.  
  73.     if (!(GInfoPtr = setupGelSys(MainWindowPtr->RPort, 0x03)))
  74.     {   DisplayAlert(AT_Recovery, "\0\20\20Saga: Can't set up GELs!\0", 24);
  75.         cleanexit(EXIT_FAILURE);
  76.     }
  77.     NewBob.nb_RasDepth = DisplayDepth;
  78.  
  79.     NewBob.nb_PlaneOnOff = 114;
  80.     for (whichhero = 0; whichhero <= HEROES; whichhero++)
  81.     {   NewBob.nb_Image = HeroData[whichhero];
  82.         if (!(HeroBobPtr[whichhero] = makeBob(&NewBob)))
  83.         {   DisplayAlert(AT_Recovery, "\0\20\20Saga: Can't make hero bob(s)!\0", 24);
  84.             cleanexit(EXIT_FAILURE);
  85.         }
  86.         AddBob(HeroBobPtr[whichhero], MainWindowPtr->RPort);
  87.     }
  88.  
  89.     NewBob.nb_PlaneOnOff = 116;
  90.     for (whichjarl = 0; whichjarl <= JARLS; whichjarl++)
  91.     {   NewBob.nb_Image = UnknownJarlData;
  92.         if (!(JarlBobPtr[whichjarl] = makeBob(&NewBob)))
  93.         {   DisplayAlert(AT_Recovery, "\0\20\20Saga: Can't make jarl bob(s)!\0", 24);
  94.             cleanexit(EXIT_FAILURE);
  95.         }
  96.         AddBob(JarlBobPtr[whichjarl], MainWindowPtr->RPort);
  97.     }
  98.  
  99.     NewBob.nb_PlaneOnOff = 118;
  100.     for (whichmonster = 0; whichmonster <= MONSTERS; whichmonster++)
  101.     {   NewBob.nb_Image = MonsterData[whichmonster];
  102.         if (!(MonsterBobPtr[whichmonster] = makeBob(&NewBob)))
  103.         {   DisplayAlert(AT_Recovery, "\0\20\20Saga: Can't make monster bob(s)!\0", 24);
  104.             cleanexit(EXIT_FAILURE);
  105.         }
  106.         AddBob(MonsterBobPtr[whichmonster], MainWindowPtr->RPort);
  107.     }
  108.  
  109.     NewBob.nb_PlaneOnOff = 120;
  110.     for (whichsord = 0; whichsord <= SORDS; whichsord++)
  111.     {   NewBob.nb_Image = SordData[whichsord];
  112.         if (!(SordBobPtr[whichsord] = makeBob(&NewBob)))
  113.         {   DisplayAlert(AT_Recovery, "\0\20\20Saga: Can't make sword bob(s)!\0", 24);
  114.             cleanexit(EXIT_FAILURE);
  115.         }
  116.         AddBob(SordBobPtr[whichsord], MainWindowPtr->RPort);
  117.     }
  118.  
  119.     NewBob.nb_PlaneOnOff = 122;
  120.     for (whichtreasure = 0; whichtreasure <= TREASURES; whichtreasure++)
  121.     {   NewBob.nb_Image = TreasureData[whichtreasure];
  122.         if (!(TreasureBobPtr[whichtreasure] = makeBob(&NewBob)))
  123.         {   DisplayAlert(AT_Recovery, "\0\20\20Saga: Can't make treasure bob(s)!\0", 24);
  124.             cleanexit(EXIT_FAILURE);
  125.         }
  126.         AddBob(TreasureBobPtr[whichtreasure], MainWindowPtr->RPort);
  127. }   }
  128.  
  129. AGLOBAL void destroycounters(void)
  130. {   SLONG whichhero, whichjarl, whichmonster, whichtreasure, whichsord;
  131.  
  132.     for (whichhero = 0; whichhero <= HEROES; whichhero++)
  133.     {   if (HeroBobPtr[whichhero])
  134.         {   remove_hero(whichhero, FALSE);
  135.             RemBob(HeroBobPtr[whichhero]);
  136.     }   }
  137.     for (whichjarl = 0; whichjarl <= JARLS; whichjarl++)
  138.     {   if (JarlBobPtr[whichjarl])
  139.         {   remove_jarl(whichjarl, FALSE);
  140.             RemBob(JarlBobPtr[whichjarl]);
  141.     }   }
  142.     for (whichmonster = 0; whichmonster <= MONSTERS; whichmonster++)
  143.     {   if (MonsterBobPtr[whichmonster])
  144.         {   remove_monster(whichmonster, FALSE);
  145.             RemBob(MonsterBobPtr[whichmonster]);
  146.     }   }
  147.     for (whichtreasure = 0; whichtreasure <= TREASURES; whichtreasure++)
  148.     {   if (TreasureBobPtr[whichtreasure])
  149.         {   remove_treasure(whichtreasure, FALSE);
  150.             RemBob(TreasureBobPtr[whichtreasure]);
  151.     }   }
  152.     for (whichsord = 0; whichsord <= SORDS; whichsord++)
  153.     {   if (SordBobPtr[whichsord])
  154.         {   remove_sord(whichsord, FALSE);
  155.             RemBob(SordBobPtr[whichsord]);
  156.     }   }
  157.  
  158.     /* if (GInfoPtr)
  159.     {   refreshcounters();
  160.     } */
  161.     for (whichhero = 0; whichhero <= HEROES; whichhero++)
  162.     {   if (HeroBobPtr[whichhero])
  163.         {   freeBob(HeroBobPtr[whichhero], NewBob.nb_RasDepth);
  164.             HeroBobPtr[whichhero] = NULL;
  165.     }   }
  166.     for (whichjarl = 0; whichjarl <= JARLS; whichjarl++)
  167.     {   if (JarlBobPtr[whichjarl])
  168.         {   freeBob(JarlBobPtr[whichjarl], NewBob.nb_RasDepth);
  169.             JarlBobPtr[whichjarl] = NULL;
  170.     }   }
  171.     for (whichmonster = 0; whichmonster <= MONSTERS; whichmonster++)
  172.     {   if (MonsterBobPtr[whichmonster])
  173.         {   freeBob(MonsterBobPtr[whichmonster], NewBob.nb_RasDepth);
  174.             MonsterBobPtr[whichmonster] = NULL;
  175.     }   }
  176.     for (whichtreasure = 0; whichtreasure <= TREASURES; whichtreasure++)
  177.     {   if (TreasureBobPtr[whichtreasure])
  178.         {   freeBob(TreasureBobPtr[whichtreasure], NewBob.nb_RasDepth);
  179.             TreasureBobPtr[whichtreasure] = NULL;
  180.     }   }
  181.     for (whichsord = 0; whichsord <= SORDS; whichsord++)
  182.     {   if (SordBobPtr[whichsord])
  183.         {   freeBob(SordBobPtr[whichsord], NewBob.nb_RasDepth);
  184.             SordBobPtr[whichsord] = NULL;
  185.     }   }
  186.  
  187.     if (GInfoPtr)
  188.     {   cleanupGelSys(GInfoPtr, MainWindowPtr->RPort);
  189. }   }
  190.  
  191. AGLOBAL void unslot_hero(SLONG whichhero)
  192. {   if (hero[whichhero].slot != -1)
  193.     {   world[hero[whichhero].where].slot[hero[whichhero].slot] = FALSE;
  194.         hero[whichhero].slot = -1;
  195. }   }
  196. AGLOBAL void unslot_jarl(SLONG whichjarl)
  197. {   if (jarl[whichjarl].slot != -1)
  198.     {   world[jarl[whichjarl].where].slot[jarl[whichjarl].slot] = FALSE;
  199.         jarl[whichjarl].slot = -1;
  200. }   }
  201. AGLOBAL void unslot_monster(SLONG whichmonster)
  202. {   if (monster[whichmonster].slot != -1)
  203.     {   world[monster[whichmonster].where].slot[monster[whichmonster].slot] = FALSE;
  204.         monster[whichmonster].slot = -1;
  205. }   }
  206. AGLOBAL void unslot_treasure(SLONG whichtreasure)
  207. {   if (treasure[whichtreasure].slot != -1)
  208.     {   world[treasure[whichtreasure].where].slot[treasure[whichtreasure].slot] = FALSE;
  209.         treasure[whichtreasure].slot = -1;
  210. }   }
  211. AGLOBAL void unslot_sord(SLONG whichsord)
  212. {   if (sord[whichsord].slot != -1)
  213.     {   world[sord[whichsord].where].slot[sord[whichsord].slot] = FALSE;
  214.         sord[whichsord].slot = -1;
  215. }   }
  216.  
  217. AGLOBAL void move_hero(SLONG whichhero, FLAG display)
  218. {   SLONG whichslot;
  219.  
  220.     // This assumes the counter has already been unslotted from its old
  221.     // location.
  222.     for (whichslot = 0; whichslot <= SLOTS; whichslot++)
  223.     {   if (!(world[hero[whichhero].where].slot[whichslot]))
  224.         {   hero[whichhero].slot = whichslot;
  225.             break;
  226.     }   }
  227.     world[hero[whichhero].where].slot[whichslot] = TRUE;
  228.  
  229.     HeroBobPtr[whichhero]->BobVSprite->X = world[hero[whichhero].where].centrex - 12;
  230.     HeroBobPtr[whichhero]->BobVSprite->Y = world[hero[whichhero].where].centrey - 12 - (whichslot * 7);
  231.     if (display)
  232.     {   refreshcounters();
  233. }   }
  234. AGLOBAL void move_monster(SLONG whichmonster, FLAG display)
  235. {   SLONG whichslot;
  236.  
  237.     // This assumes the counter has already been unslotted from its old
  238.     // location.
  239.     for (whichslot = 0; whichslot <= SLOTS; whichslot++)
  240.     {   if (!(world[monster[whichmonster].where].slot[whichslot]))
  241.         {   monster[whichmonster].slot = whichslot;
  242.             break;
  243.     }   }
  244.     world[monster[whichmonster].where].slot[whichslot] = TRUE;
  245.  
  246.     MonsterBobPtr[whichmonster]->BobVSprite->X = world[monster[whichmonster].where].centrex - 12;
  247.     MonsterBobPtr[whichmonster]->BobVSprite->Y = world[monster[whichmonster].where].centrey - 12 - (whichslot * 7);
  248.     if (display)
  249.     {   refreshcounters();
  250. }   }
  251. AGLOBAL void move_jarl(SLONG whichjarl, FLAG display)
  252. {   SLONG whichslot;
  253.  
  254.     // This assumes the counter has already been unslotted from its old
  255.     // location.
  256.     for (whichslot = 0; whichslot <= SLOTS; whichslot++)
  257.     {   if (!(world[jarl[whichjarl].where].slot[whichslot]))
  258.         {   jarl[whichjarl].slot = whichslot;
  259.             break;
  260.     }   }
  261.     world[jarl[whichjarl].where].slot[whichslot] = TRUE;
  262.  
  263.     JarlBobPtr[whichjarl]->BobVSprite->X = world[jarl[whichjarl].where].centrex - 12;
  264.     JarlBobPtr[whichjarl]->BobVSprite->Y = world[jarl[whichjarl].where].centrey - 12 - (whichslot * 7);
  265.     if (display)
  266.     {   refreshcounters();
  267. }   }
  268. AGLOBAL void move_treasure(SLONG whichtreasure, FLAG display)
  269. {   SLONG whichslot;
  270.  
  271.     // This assumes the counter has already been unslotted from its old
  272.     // location.
  273.     for (whichslot = 0; whichslot <= SLOTS; whichslot++)
  274.     {   if (!(world[treasure[whichtreasure].where].slot[whichslot]))
  275.         {   treasure[whichtreasure].slot = whichslot;
  276.             break;
  277.     }   }
  278.     world[treasure[whichtreasure].where].slot[whichslot] = TRUE;
  279.  
  280.     TreasureBobPtr[whichtreasure]->BobVSprite->X = world[treasure[whichtreasure].where].centrex - 12;
  281.     TreasureBobPtr[whichtreasure]->BobVSprite->Y = world[treasure[whichtreasure].where].centrey - 12 - (whichslot * 7);
  282.     if (display)
  283.     {   refreshcounters();
  284. }   }
  285. AGLOBAL void move_sord(SLONG whichsord, FLAG display)
  286. {   SLONG whichslot;
  287.  
  288.     // This assumes the counter has already been unslotted from its old
  289.     // location.
  290.     for (whichslot = 0; whichslot <= SLOTS; whichslot++)
  291.     {   if (!(world[sord[whichsord].where].slot[whichslot]))
  292.         {   sord[whichsord].slot = whichslot;
  293.             break;
  294.     }   }
  295.     world[sord[whichsord].where].slot[whichslot] = TRUE;
  296.  
  297.     SordBobPtr[whichsord]->BobVSprite->X = world[sord[whichsord].where].centrex - 12;
  298.     SordBobPtr[whichsord]->BobVSprite->Y = world[sord[whichsord].where].centrey - 12 - (whichslot * 7);
  299.     if (display)
  300.     {   refreshcounters();
  301. }   }
  302.  
  303. AGLOBAL void init_counters(void)
  304. {   SLONG whichhero, whichjarl, whichmonster, whichtreasure, whichsord;
  305.  
  306.     for (whichhero = 0; whichhero <= HEROES; whichhero++)
  307.     {   hero[whichhero].slot = -1;
  308.         HeroBobPtr[whichhero] = NULL;
  309.     }
  310.     for (whichjarl = 0; whichjarl <= JARLS; whichjarl++)
  311.     {   jarl[whichjarl].slot = -1;
  312.         JarlBobPtr[whichjarl] = NULL;
  313.     }
  314.     for (whichmonster = 0; whichmonster <= MONSTERS; whichmonster++)
  315.     {   monster[whichmonster].slot = -1;
  316.         MonsterBobPtr[whichmonster] = NULL;
  317.     }
  318.     for (whichtreasure = 0; whichtreasure <= TREASURES; whichtreasure++)
  319.     {   treasure[whichtreasure].slot = -1;
  320.         TreasureBobPtr[whichtreasure] = NULL;
  321.     }
  322.     for (whichsord = 0; whichsord <= SORDS; whichsord++)
  323.     {   sord[whichsord].slot = -1;
  324.         SordBobPtr[whichsord] = NULL;
  325. }   }
  326.  
  327. AGLOBAL void revealjarl(SLONG whichjarl, FLAG display)
  328. {   jarl[whichjarl].face        = FACEUP;
  329.     jarl[whichjarl].recruitable = TRUE;
  330.     JarlBobPtr[whichjarl]->BobVSprite->ImageData = JarlData[whichjarl];
  331.     // InitMasks(JarlBobPtr[whichjarl]->BobVSprite);
  332.     if (display)
  333.     {   refreshcounters();
  334. }   }
  335.  
  336. AGLOBAL void hidejarl(SLONG whichjarl, FLAG display)
  337. {   jarl[whichjarl].face        = FACEDOWN;
  338.     jarl[whichjarl].recruitable = FALSE;
  339.     JarlBobPtr[whichjarl]->BobVSprite->ImageData = UnknownJarlData;
  340.     // InitMasks(JarlBobPtr[whichjarl]->BobVSprite);
  341.     if (display)
  342.     {   refreshcounters();
  343. }   }
  344.  
  345. AGLOBAL SLONG checkcounters(SWORD mousex, SWORD mousey, SLONG* countertype)
  346. {   SLONG foundy,
  347.           whichhero,
  348.           whichcounter = -1,
  349.           whichjarl,
  350.           whichmonster,
  351.           whichtreasure, whichsord;
  352.     FLAG  found = FALSE;
  353.  
  354.     *(countertype) = -1;
  355.  
  356.     /* This assumes that counters with higher y-values (ie. lower on the
  357.     screen) have higher priority than those with lower y-values. */
  358.  
  359.     // find all counters lying under the pointer
  360.     for (whichhero = 0; whichhero <= HEROES; whichhero++)
  361.     {   if
  362.         (   mousex >= HeroBobPtr[whichhero]->BobVSprite->X
  363.          && mousex <= HeroBobPtr[whichhero]->BobVSprite->X + 24 - 1
  364.          && mousey >= HeroBobPtr[whichhero]->BobVSprite->Y
  365.          && mousey <= HeroBobPtr[whichhero]->BobVSprite->Y + 24 - 1
  366.         )
  367.         {   hero[whichhero].foundbob = TRUE;
  368.             found = TRUE;
  369.     }   }
  370.     for (whichjarl = 0; whichjarl <= JARLS; whichjarl++)
  371.     {   if
  372.         (   mousex >= JarlBobPtr[whichjarl]->BobVSprite->X
  373.          && mousex <= JarlBobPtr[whichjarl]->BobVSprite->X + 24 - 1
  374.          && mousey >= JarlBobPtr[whichjarl]->BobVSprite->Y
  375.          && mousey <= JarlBobPtr[whichjarl]->BobVSprite->Y + 24 - 1
  376.         )
  377.         {   jarl[whichjarl].foundbob = TRUE;
  378.             found = TRUE;
  379.     }   }
  380.     for (whichmonster = 0; whichmonster <= MONSTERS; whichmonster++)
  381.     {   if
  382.         (   mousex >= MonsterBobPtr[whichmonster]->BobVSprite->X
  383.          && mousex <= MonsterBobPtr[whichmonster]->BobVSprite->X + 24 - 1
  384.          && mousey >= MonsterBobPtr[whichmonster]->BobVSprite->Y
  385.          && mousey <= MonsterBobPtr[whichmonster]->BobVSprite->Y + 24 - 1
  386.         )
  387.         {   monster[whichmonster].foundbob = TRUE;
  388.             found = TRUE;
  389.     }   }
  390.     for (whichtreasure = 0; whichtreasure <= TREASURES; whichtreasure++)
  391.     {   if
  392.         (   mousex >= TreasureBobPtr[whichtreasure]->BobVSprite->X
  393.          && mousex <= TreasureBobPtr[whichtreasure]->BobVSprite->X + 24 - 1
  394.          && mousey >= TreasureBobPtr[whichtreasure]->BobVSprite->Y
  395.          && mousey <= TreasureBobPtr[whichtreasure]->BobVSprite->Y + 24 - 1
  396.         )
  397.         {   treasure[whichtreasure].foundbob = TRUE;
  398.             found = TRUE;
  399.     }   }
  400.     for (whichsord = 0; whichsord <= SORDS; whichsord++)
  401.     {   if
  402.         (   mousex >= SordBobPtr[whichsord]->BobVSprite->X
  403.          && mousex <= SordBobPtr[whichsord]->BobVSprite->X + 24 - 1
  404.          && mousey >= SordBobPtr[whichsord]->BobVSprite->Y
  405.          && mousey <= SordBobPtr[whichsord]->BobVSprite->Y + 24 - 1
  406.         )
  407.         {   sord[whichsord].foundbob = TRUE;
  408.             found = TRUE;
  409.     }   }
  410.  
  411.     if (!found)
  412.     {   return(-1);
  413.     }
  414.  
  415.     // determine which counter is topmost (ie. which is lower on the screen)
  416.     foundy = -1;
  417.     for (whichhero = 0; whichhero <= HEROES; whichhero++)
  418.     {   if
  419.         (   hero[whichhero].foundbob
  420.          && HeroBobPtr[whichhero]->BobVSprite->Y > foundy
  421.         )
  422.         {   whichcounter = whichhero;
  423.             *(countertype) = HERO;
  424.             foundy = HeroBobPtr[whichhero]->BobVSprite->Y;
  425.         }
  426.         hero[whichhero].foundbob = FALSE;
  427.     }
  428.     for (whichjarl = 0; whichjarl <= JARLS; whichjarl++)
  429.     {   if
  430.         (   jarl[whichjarl].foundbob
  431.          && JarlBobPtr[whichjarl]->BobVSprite->Y > foundy
  432.         )
  433.         {   whichcounter = whichjarl;
  434.             *(countertype) = JARL;
  435.             foundy = JarlBobPtr[whichjarl]->BobVSprite->Y;
  436.         }
  437.         jarl[whichjarl].foundbob = FALSE;
  438.     }
  439.     for (whichmonster = 0; whichmonster <= MONSTERS; whichmonster++)
  440.     {   if
  441.         (   monster[whichmonster].foundbob
  442.          && MonsterBobPtr[whichmonster]->BobVSprite->Y > foundy
  443.         )
  444.         {   whichcounter = whichmonster;
  445.             *(countertype) = MONSTER;
  446.             foundy = MonsterBobPtr[whichmonster]->BobVSprite->Y;
  447.         }
  448.         monster[whichmonster].foundbob = FALSE;
  449.     }
  450.     for (whichtreasure = 0; whichtreasure <= TREASURES; whichtreasure++)
  451.     {   if
  452.         (   treasure[whichtreasure].foundbob
  453.          && TreasureBobPtr[whichtreasure]->BobVSprite->Y > foundy
  454.         )
  455.         {   whichcounter = whichtreasure;
  456.             *(countertype) = TREASURE;
  457.             foundy = TreasureBobPtr[whichtreasure]->BobVSprite->Y;
  458.         }
  459.         treasure[whichtreasure].foundbob = FALSE;
  460.     }
  461.     for (whichsord = 0; whichsord <= SORDS; whichsord++)
  462.     {   if
  463.         (   sord[whichsord].foundbob
  464.          && SordBobPtr[whichsord]->BobVSprite->Y > foundy
  465.         )
  466.         {   whichcounter = whichsord;
  467.             *(countertype) = SORD;
  468.             foundy = SordBobPtr[whichsord]->BobVSprite->Y;
  469.         }
  470.         sord[whichsord].foundbob = FALSE;
  471.     }
  472.  
  473.     return(whichcounter);
  474. }
  475.  
  476. AGLOBAL void select_hero(SLONG whichhero, FLAG display)
  477. {   if (hero[whichhero].promoted != -1)
  478.     {   HeroBobPtr[whichhero]->BobVSprite->ImageData = JarlData[hero[whichhero].promoted];
  479.     } else
  480.     {   HeroBobPtr[whichhero]->BobVSprite->ImageData = HeroData[whichhero];
  481.     }
  482.     HeroBobPtr[whichhero]->BobVSprite->PlaneOnOff = 124;
  483.     // InitMasks(HeroBobPtr[whichhero]->BobVSprite);
  484.     if (display)
  485.     {   refreshcounters();
  486. }   }
  487. AGLOBAL void deselect_hero(SLONG whichhero, FLAG display)
  488. {   if (hero[whichhero].promoted != -1)
  489.     {   HeroBobPtr[whichhero]->BobVSprite->ImageData = JarlData[hero[whichhero].promoted];
  490.     } else
  491.     {   HeroBobPtr[whichhero]->BobVSprite->ImageData = HeroData[whichhero];
  492.     }
  493.     HeroBobPtr[whichhero]->BobVSprite->PlaneOnOff = 114;
  494.     // InitMasks(HeroBobPtr[whichhero]->BobVSprite);
  495.     if (display)
  496.     {   refreshcounters();
  497. }   }
  498. AGLOBAL void select_jarl(SLONG whichjarl, FLAG display)
  499. {   JarlBobPtr[whichjarl]->BobVSprite->PlaneOnOff = 124;
  500.     // InitMasks(JarlBobPtr[whichjarl]->BobVSprite);
  501.     if (display)
  502.     {   refreshcounters();
  503. }   }
  504. AGLOBAL void deselect_jarl(SLONG whichjarl, FLAG display)
  505. {   JarlBobPtr[whichjarl]->BobVSprite->PlaneOnOff = 116;
  506.     // InitMasks(JarlBobPtr[whichjarl]->BobVSprite);
  507.     if (display)
  508.     {   refreshcounters();
  509. }   }
  510. AGLOBAL void select_monster(SLONG whichmonster, FLAG display)
  511. {   MonsterBobPtr[whichmonster]->BobVSprite->PlaneOnOff = 124;
  512.     // InitMasks(MonsterBobPtr[whichmonster]->BobVSprite);
  513.     if (display)
  514.     {   refreshcounters();
  515. }   }
  516. AGLOBAL void deselect_monster(SLONG whichmonster, FLAG display)
  517. {   MonsterBobPtr[whichmonster]->BobVSprite->PlaneOnOff = 118;
  518.     // InitMasks(JarlBobPtr[whichjarl]->BobVSprite);
  519.     if (display)
  520.     {   refreshcounters();
  521. }   }
  522.  
  523. AGLOBAL void remove_hero(SLONG whichhero, FLAG display)
  524. {   unslot_hero(whichhero);
  525.     HeroBobPtr[whichhero]->BobVSprite->X = HIDDEN_X;
  526.     HeroBobPtr[whichhero]->BobVSprite->Y = HIDDEN_Y;
  527.     if (display)
  528.     {   refreshcounters();
  529. }   }
  530. AGLOBAL void remove_jarl(SLONG whichjarl, FLAG display)
  531. {   unslot_jarl(whichjarl);
  532.     JarlBobPtr[whichjarl]->BobVSprite->X = HIDDEN_X;
  533.     JarlBobPtr[whichjarl]->BobVSprite->Y = HIDDEN_Y;
  534.     if (display)
  535.     {   refreshcounters();
  536. }   }
  537. AGLOBAL void remove_monster(SLONG whichmonster, FLAG display)
  538. {   unslot_monster(whichmonster);
  539.     MonsterBobPtr[whichmonster]->BobVSprite->X = HIDDEN_X;
  540.     MonsterBobPtr[whichmonster]->BobVSprite->Y = HIDDEN_Y;
  541.     if (display)
  542.     {   refreshcounters();
  543. }   }
  544. AGLOBAL void remove_treasure(SLONG whichtreasure, FLAG display)
  545. {   unslot_treasure(whichtreasure);
  546.     TreasureBobPtr[whichtreasure]->BobVSprite->X = HIDDEN_X;
  547.     TreasureBobPtr[whichtreasure]->BobVSprite->Y = HIDDEN_Y;
  548.     if (display)
  549.     {   refreshcounters();
  550. }   }
  551. AGLOBAL void remove_sord(SLONG whichsord, FLAG display)
  552. {   unslot_sord(whichsord);
  553.     SordBobPtr[whichsord]->BobVSprite->X = HIDDEN_X;
  554.     SordBobPtr[whichsord]->BobVSprite->Y = HIDDEN_Y;
  555.     if (display)
  556.     {   refreshcounters();
  557. }   }
  558.  
  559. AGLOBAL void refreshcounters(void)
  560. {   /* Unfortunately, it would seem that the DrawGList() call turns the
  561.     display back on automatically */
  562.  
  563.     screenoff();
  564.     SortGList(MainWindowPtr->RPort);
  565.     DrawGList(MainWindowPtr->RPort, ViewPortAddress(MainWindowPtr));
  566.     screenon();
  567. }
  568.  
  569. AGLOBAL void reset_images(void)
  570. {   SLONG whichhero;
  571.  
  572.     for (whichhero = 0; whichhero <= HEROES; whichhero++)
  573.     {   HeroBobPtr[whichhero]->BobVSprite->ImageData = HeroData[whichhero];
  574.         // InitMasks(HeroBobPtr[whichhero]->BobVSprite);
  575. }   }
  576.  
  577. AGLOBAL void info(SLONG countertype, SLONG counter)
  578. {   SLONG infobobs = 0,
  579.           which;
  580.  
  581.     // If we have a jarl with five or six treasures, the fifth and sixth
  582.     // treasure counters will not fit into the window.
  583.  
  584.     for (which = 0; which <= TREASURES; which++)
  585.     {   if
  586.         (   treasure[which].possessortype == countertype
  587.          && treasure[which].possessor     == counter
  588.         )
  589.         {   Counter.ImageData  = TreasureData[which];
  590.             Counter.PlaneOnOff = 122;
  591.             DrawImage(InfoWindowPtr->RPort, &Counter, 600, 16 + (infobobs * (24 + 4)));
  592.             infobobs++;
  593.     }   }
  594.  
  595.     infobobs = 0;
  596.     for (which = 0; which <= SORDS; which++)
  597.     {   if
  598.         (   sord[which].possessortype == countertype
  599.          && sord[which].possessor     == counter
  600.         )
  601.         {   Counter.ImageData  = SordData[which];
  602.             Counter.PlaneOnOff = 120;
  603.             DrawImage(InfoWindowPtr->RPort, &Counter, 572, 16);
  604.             infobobs = 1;
  605.             break;
  606.     }   }
  607.     if (countertype == HERO)
  608.     {   for (which = 0; which <= JARLS; which++)
  609.         {   if
  610.             (   jarl[which].alive
  611.              && jarl[which].hero == counter
  612.             )
  613.             {   Counter.ImageData  = JarlData[which];
  614.                 Counter.PlaneOnOff = 116;
  615.                 DrawImage(InfoWindowPtr->RPort, &Counter, 572, 16 + (infobobs * (24 + 4)));
  616.                 infobobs++;
  617. }   }   }   }
  618.  
  619. AGLOBAL void doc(SLONG number)
  620. {   SLONG which;
  621.  
  622.     if (number == 3) // swords
  623.     {   Counter.PlaneOnOff = 120;
  624.         for (which = 0; which <= SORDS; which++)
  625.         {   Counter.ImageData  = SordData[which];
  626.             DrawImage(InfoWindowPtr->RPort, &Counter, 16, sord[which].y);
  627.         }
  628.     } elif (number == 4) // treasures
  629.     {   Counter.PlaneOnOff = 122;
  630.         for (which = 0; which <= treasures; which++)
  631.         {   Counter.ImageData  = TreasureData[which];
  632.             DrawImage(InfoWindowPtr->RPort, &Counter, 16, treasure[which].y);
  633. }   }   }
  634.  
  635.